package com.pllandxzx.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pll.dto.ResponseDto;
import com.pll.pojo.Ruler;
import com.pllandxzx.mapper.FeeRulesMapper;
import com.pllandxzx.service.FeeRulesService;
import com.pllandxzx.vo.FeeRuleVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName FeeRulesServiceImpl
 * @Description TODO
 * @Author 小鹿
 * @Date 2025/6/8 17:41
 */

@Service
public class FeeRulesServiceImpl implements FeeRulesService
{
    @Autowired
    private FeeRulesMapper feeRulesMapper;

    //  查询所有收费规则 并分页返回
    @Override
    public ResponseDto getAllFeeRules(int page, int pageSize)
    {
        // 当前页，每页大小
        Page<Ruler> rulerPage = new Page<>(page, pageSize);
        IPage<Ruler> allFeeRules = feeRulesMapper.getAllFeeRules(rulerPage);
        System.out.println(allFeeRules.getRecords());
        if (allFeeRules!=null){
            return ResponseDto.success(allFeeRules);
        }
        return ResponseDto.err(405,"未查询到任何规则");
    }

    //  删除收费规则
    @Override
    public ResponseDto deleteFeeRules(Integer id)
    {
        if (feeRulesMapper.deleteFeeRules(id)>0){
            return ResponseDto.success("删除成功");
        }
        return ResponseDto.fail(405,"删除失败");
    }

    // 新增收费规则
    @Override
    public ResponseDto addFeeRule(FeeRuleVo data)
    {
        if (feeRulesMapper.addFeeRule(data)>0){
            return ResponseDto.success("新增成功");
        }
        return ResponseDto.fail(405,"新增失败");
    }

    //  修改收费规则
    @Override
    public ResponseDto updateFeeRule(Integer id,FeeRuleVo data)
    {
        if (feeRulesMapper.updateFeeRule(id,data)>0){
            return ResponseDto.success("修改成功");
        }
        return ResponseDto.fail(405,"修改失败");
    }
}